package com.ck.demo;

import com.alibaba.fastjson.JSONObject;

public class JsonDemo {

    static String jsonStr = "{\"code\":\"200\",\"message\":\"success\",\"body\":{\"groups\":{\"2022-09-05\":{\"dataList\":[{\"collectTime\":\"2022-03-20 22:23:57\",\"cameraName\":\"camera1\",\"positionName\":\"camera1\"}]},\"2022-09-04\":{\"dataList\":[{\"collectTime\":\"2022-03-20 22:23:57\",\"cameraName\":\"camera3\",\"positionName\":\"camera3\"},{\"collectTime\":\"2022-03-20 22:23:57\",\"cameraName\":\"camera4\",\"positionName\":\"camera4\"}]}}}}";

    public static void main(String[] args) {
        System.out.println("当前json:\n"+jsonStr);
        System.out.println();
        JSONObject jsonObject = JSONObject.parseObject(jsonStr);
        JSONObject groupsJson = jsonObject.getJSONObject("body").getJSONObject("groups");
        System.out.println("group:\n"+groupsJson);
        getDataListByDate(groupsJson,"2022-09-04");
    }

    public static void getDataListByDate(JSONObject groupsJson,String date) {
        JSONObject jsonObject = groupsJson.getJSONObject(date);
        System.out.println("请求时间:"+date);
        System.out.println("对应数据:"+jsonObject);
    }
}
